package com.logic.saas.util;

import java.util.Random;

public class RandomUtil {
	public static String genRandomString(int length) {
		final int maxNum = 62;
		int i;
		int count = 0;
		char[] str = { 	'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
						'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',						
						'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};

		StringBuffer sb = new StringBuffer("");
		Random r = new Random();
		while (count < length) {
			i = Math.abs(r.nextInt(maxNum));

			if (i >= 0 && i < str.length) {
				sb.append(str[i]);
				count++;
			}
		}

		return sb.toString();
	} 	
	
	/*
	public static String generateComanyCode(String userId){
		StringBuffer sb = new StringBuffer();
		sb.append(RandomUtil.genRandomString(5));
		sb.append("-").append(RandomUtil.genRandomString(5));
		sb.append("-").append(RandomUtil.genRandomString(5));
		sb.append("-").append(RandomUtil.genRandomString(5));
		if(userId.length() < 5){
			int i = 5 - userId.length();
			for(int j = 0; j < i; j++ ){
				sb.append("0");
			}
			sb.append(userId);
		}else{
			sb.append(userId.substring(userId.length()-5, userId.length()));
		}
		return sb.toString().toUpperCase();
	}
	*/
}
